#pragma once
#include "Singleton.h"
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "tool/RingQueue.h"
#include "worker/Worker.h"
#include "worker/Camera.h"


// TODO 分到个define.h里面去
enum HttpMsgType{
	HttpMsgType_None,
	HttpMsgType_TaskUpload,	// 普通任务上传

};

class HttpMsg{
public:
	HttpMsgType type;
	std::string msg;
	HttpMsg(){}
	HttpMsg(HttpMsgType type, const std::string& msg){this->type = type; this->msg = msg;}
};

class WorkerMgr : public Singleton<WorkerMgr>
{
public:
	int Init(const std::string& conf_file);
	void Run();
	std::shared_ptr<CameraInfo> GetCameraInfo(int id);
	std::shared_ptr<TaskInfo> GetTaskInfo(int type, int id);
	void SyncCamList();
	void SyncTaskList();
	void SyncSkillList();
	void DoUpdate();

	void Push(const HttpMsg& msg);
protected:
	friend class Singleton<WorkerMgr>;
	WorkerMgr() {}
	~WorkerMgr() {}
	void _Run();
	void DoHttpMsg();
private:
	std::thread m_thread;
	RingQueue<HttpMsg, 1000> m_msgs;
	bool m_exit = false;	// 是否结束
	
	std::map<int, std::shared_ptr<CameraInfo>> m_cameras;	// 摄像机信息 (包含 Worker)
	std::map<std::pair<int, int>, std::shared_ptr<TaskInfo>>	m_tasks;			// 任务信息 用来比对 key值为 类型+Id

	std::vector<std::shared_ptr<Worker>> m_workers;			// 工人列表

	std::vector<int> m_queue;	// 轮询队列
	// 配置参数
	int m_interval;
};
